package com.yhgm.model.vo;


import cn.hutool.json.JSONUtil;
import com.yhgm.model.entity.Roles;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @Author: yh
 * @Date: 2024/3/24
 */
@Data
public class RoleVO implements Serializable {
    /**
     * id
     */
    private Long id;

    /**
     * 用户角色
     */
    private String userRole;

    /**
     * 角色中文名
     */
    private String name;
    /**
     * 角色描述
     */
    private String profile;

    /**
     * 角色启用状态
     */
    private Integer status;

    /**
     * 角色创建时间
     */
    private Date createTime;

    /**
     * 角色修改时间
     */
    private Date updateTime;

    /**
     * 权限点集合
     */
    private List<Long> permIds;

    public RoleVO beanToVO(Roles roles) {
        RoleVO roleVO = new RoleVO();
        BeanUtils.copyProperties(roles, roleVO);
        String ids = roles.getPermIds();
        List<Long> permIds = JSONUtil.toList(ids, Long.class);
        roleVO.setPermIds(permIds);
        return roleVO;
    }

    public Roles vOToBean(RoleVO roleVO) {
        Roles roles = new Roles();
        BeanUtils.copyProperties(roleVO, roles);
        List<Long> permIds = roleVO.getPermIds();
        String ids = JSONUtil.toJsonStr(permIds);
        roles.setPermIds(ids);
        return roles;
    }

    private static final long serialVersionUID = 1L;
}
